package com.requiem.hist_group_manage_springboot.exception;

import com.requiem.hist_group_manage_springboot.constants.SystemConstants;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@CommonsLog
public class GlobalExceptionHandler {
    @ExceptionHandler(value = {Exception.class})
    public R globalException(Exception e) {
        StackTraceElement[] stackTrace = e.getStackTrace();
        log.info("异常：【" + e.getMessage() + "】，可能在：【" + stackTrace[0].getFileName() + "】 的第 【" + stackTrace[0].getLineNumber() + "】 行");
        return R.error(SystemConstants.PARAM_ERROR, SystemConstants.PARAM_ERROR_MSG);
    }

    @ExceptionHandler(value = {iException.class})
    public R iException(iException ie) {
        log.info("自定义异常：" + ie.getMessage());
        return R.error(ie.getCode(), ie.getMessage());
    }

}
